﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DCTLib.Common;
using System.Data;

namespace DCTAccess.Business.LevelConfig
{
    public class LevelFilter
    {
        private int _id = -1;
        private int _level = -1;
        private int _numOfPeople = -1;
        private decimal _percent = 0;
        private string _sortOrder = " ORDER BY LevelInfo ASC ";

        public decimal Percent
        {
            get { return _percent; }
            set { _percent = value; }
        }

        public int NumOfPeople
        {
            get { return _numOfPeople; }
            set { _numOfPeople = value; }
        }

        public int Level1
        {
            get { return _level; }
            set { _level = value; }
        }

        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

         private string SelectAll
            {
                get
                {
                    StringBuilder sql = new StringBuilder();
                    sql.Append("SELECT ID,LevelInfo, NumOfPeople, [percent] ");                    
                    sql.Append("FROM LevelConfigs ");
                    sql.Append("WHERE valid = 1 ");
                    return sql.ToString();
                }
            }
            

            public DataTable GetConfigPercent()
            {
                SQLHelper sqlHelper = new SQLHelper();
                sqlHelper.SwitchCommandType(CommandType.Text);

                StringBuilder sql = new StringBuilder(SelectAll);

               if (Level1 != -1)
                {
                    sql.Append("AND " + IntegerCompareSQLBuilder.GetSQL("LevelInfo", IntegerCompareTypes.Equals, "@LevelInfo"));
                    sqlHelper.AddParameter("@LevelInfo", Level1);
                }  

                sql.Append(_sortOrder);
                return sqlHelper.GetDataTable(sql.ToString());
            }
    }
}
